package testing;

import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

import java.util.ArrayList;

import org.junit.Test;

import poker.Action;
import poker.GameRound;
import poker.Human;
import poker.Player;
import poker.Rules;
import poker.gui.GUI_Table;

public class TestRules 
{
	@Test
	public void testIsBettingRoundOverPreFlop()
	{
		GameRound gameRound = new GameRound(createPlayers(5), false);
		gameRound.dealPocketCards();
		
		ArrayList<Action> playerActions = new ArrayList<Action>(); 

		gameRound.setPlayerActions(playerActions);
		Rules.SetGameRound(gameRound);
		
		playerActions.add(Action.Call(100, null));
		playerActions.add(Action.Fold(null));
		playerActions.add(Action.Call(100, null));
		playerActions.add(Action.Fold(null));
		
		playerActions.add(Action.Call(100,null));
		playerActions.add(Action.Fold(null));
		
		assertFalse(Rules.isBettingRoundOver());
		
		playerActions.add(Action.Call(100,null));
		
		assertTrue(Rules.isBettingRoundOver());
	}
	
	@Test
	public void testIsBettingRoundOverFlop()
	{
		GameRound gameRound = new GameRound(createPlayers(3), false);
		gameRound.dealPocketCards();
		
		ArrayList<Action> playerActions = new ArrayList<Action>(); 

		gameRound.setPlayerActions(playerActions);
		Rules.SetGameRound(gameRound);

		playerActions.add(Action.Check(null));
		playerActions.add(Action.Check(null));
		
		playerActions.add(Action.Bet(200,null));
		playerActions.add(Action.Call(200,null));
		playerActions.add(Action.Raise(200,null));
		playerActions.add(Action.Fold(null));
		playerActions.add(Action.Call(200,null));
		
		assertTrue(Rules.isBettingRoundOver());
	}
	
	@Test
	public void testIsBettingRoundOverAllCheck()
	{
		GameRound gameRound = new GameRound(createPlayers(3), false);
		gameRound.dealPocketCards();
		
		ArrayList<Action> playerActions = new ArrayList<Action>(); 

		gameRound.setPlayerActions(playerActions);
		gameRound.dealFlop();
		Rules.SetGameRound(gameRound);

		playerActions.add(Action.Check(null));
		playerActions.add(Action.Check(null));
		assertFalse(Rules.isBettingRoundOver());
		playerActions.add(Action.Fold(null));
		
		assertTrue(Rules.isBettingRoundOver());
	}
	
	private ArrayList<Player> createPlayers(int num)
	{
		ArrayList<Player> players = new ArrayList<Player>();
		
		for(int i = 0; i < num; i++)
		{
			Player p = new Human(100, Integer.toString(i));
			players.add(p);
		}
		
		return players;
	}
	
	
}
